package from;

import com.sun.org.apache.xpath.internal.operations.Mod;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Check;
import org.apache.wicket.markup.html.form.CheckGroup;
import org.apache.wicket.markup.html.form.CheckGroupSelector;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.Model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CheckGroupPage extends WebPage {
    private static List SITES = new ArrayList();
    private static Map NAMES = new HashMap();
    static {
        SITES.add("http://aa.com");
        SITES.add("http://bb.com");
        SITES.add("http://cc.com");

        NAMES.put("http://aa.com", "aa");
        NAMES.put("http://bb.com", "bb");
        NAMES.put("http://cc.com", "cc");
    }

    public CheckGroupPage(){
        super();

        Form form = new Form("formCG");
        add(form);
        CheckGroup<Object> group = new CheckGroup<>("group", new ArrayList<>());
        form.add(group);
        group.add(new CheckGroupSelector("groupselector"));

        org.apache.wicket.markup.html.list.ListView sites = new ListView("sites",SITES){
            protected void populateItem(ListItem item){
                Object object = item.getModelObject();
                item.add(new Check<>("check",new Model<>(Integer.toString(item.getIndex()))));
                item.add(new Label("name",new Model<>((Serializable) NAMES.get(object))));
            };
        };
        group.add(sites);
    }
}
